package git.soulbgm.service;

import git.soulbgm.common.Constant;
import git.soulbgm.common.handle.TcpClientHandle;
import git.soulbgm.common.socket.TcpClient;
import git.soulbgm.utils.ByteUtil;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author 贺瑞杰
 * @version V1.0
 * @date 2019-04-10 10:19
 * @description
 */
@Component
public class StartTcpClient implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        TcpClient tcpClient = TcpClient.getTcpClient("127.0.0.1", 9911);
        tcpClient.start(new TcpClientHandle(tcpClient));
        Thread.sleep(1000);
        while (true) {
            Thread.sleep(1000);
            TcpClient.sendMsg(ByteUtil.byteMergerAll(new byte[]{23, 123, 121, 22, 33, 22}, Constant.TCP_DELIMITER_BYTE));
        }
    }
}
